Skip to content

gh-155864: Keep the module's current screen in step with use_screen() - #155865

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
fedonman:fix-curses-screen-use-topscreen
Aug 16, 2026
Merged

gh-155864: Keep the module's current screen in step with use_screen()#155865
serhiy-storchaka merged 1 commit into
python:mainfrom
fedonman:fix-curses-screen-use-topscreen

Conversation

@fedonman

@fedonman fedonman commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Point state->topscreen at the used screen for the duration of the screen.use() callback and restore it afterwards, which is what use_screen() itself does around set_term(). Add regression tests for the window ownership and for initscr() inside use().

The restore also undoes a set_term() performed inside the callback, which ncurses already reverts but the module did not.

$ ./python -m test test_curses -u curses
Total tests: run=170 skipped=3
Result: SUCCESS

No NEWS entry: newterm() and screen.use() are new in 3.16 and unreleased.

…reen()

screen.use() makes its screen current for the callback, but the module
kept recording the previously current screen, so newwin(), newpad() and
getwin() tagged the new window with the wrong owner.  The window then
failed to keep its own screen alive: the screen could be freed while the
window was still in use, and the next call on it read freed memory.
initscr() inside use() returned the other screen's standard window for
the same reason.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@serhiy-storchaka
serhiy-storchaka merged commit f101660 into python:main Aug 16, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants